package com.lagou.lagouserviceemail.service;

import com.lagou.api.MailApi;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

import java.time.LocalTime;

/**
 * @Authther: mrwu
 * @date:2021/4/20-04
 * @Description:com.lagou.lagouserviceemail.service
 */

@Slf4j
@DubboService
public class MailService implements MailApi{
    @Autowired
    MailSenderAutoConfiguration mailSenderAutoConfiguration;

    @Autowired
    JavaMailSender javaMailSender;
    @Override
    public boolean sendMail(String mailto, String content) {

        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom("15210371539@163.com");
        simpleMailMessage.setTo(mailto);
        simpleMailMessage.setSubject("ceshi");
        simpleMailMessage.setText(content);
        System.out.println("开始处理请求"+ LocalTime.now());
        try {
            javaMailSender.send(simpleMailMessage);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            log.error("发送邮件异常",e);
            return false;
        }
    }
}
